#include <stdint.h>
#include "ioctl.h"
  
const uint8_t lcd_init_cmd[] = {
        0xE2, /* Soft reset */
        0xFF, /* Delay */
        0x0A, /* 10ms */
        0xA2, /* Set Bias: 0xA3 1/7bias,0xA2 1/9 bias */
        0xA0, /* SEG Direction Select: b[0] = 0 normal, b[0] = 1 reverse */
        0xC8, /* COM Direction Select: b[3] = 0 normal, b[3] = 1 reverse */
        0xA6, /* Inverse Display: b[0] = 0 normal, b[0] = 1 inverse */
        0xA4, /* All pixel ON: b[0] = 0 normal, b[0] = 1 set all pixel ON */
        0x22, /* Regulation Ratio */
        0x81, /* Set Contrast (Electronic Volume Level) with the next cmd */
        0x0a, /* EV[5:0] */
        0x2F, /* Power Control Set */
        0xFF, /* Delay */
        40,   /* 40ms */
        0x40, /* Set Display Start Line */
        0xAF, /* Display On */
        0x00,
};


const uint8_t lcd_x_ofs = 0;
const uint8_t lcd_y_ofs = 0;

extern int lcd_write_reg(uint32_t reg);
extern int lcd_write_data(uint32_t x, uint32_t y, uint32_t data);

int lcd_disp_attribute(uint32_t cmd,void *arg)
{
	switch (cmd&0xff) {
        	case IOCTL_LCD_ATTRIBUTE_GRAY:
                {
                        uint32_t reg = (uint32_t )arg;
	       		if(reg>64)reg =63;
				
                       lcd_write_reg(0x81);
	               lcd_write_reg(reg);	 
               	 }
                break;
	default:
		return -2;
	}
	return 0;
}